package com.woniuxy.hrp.mapper;

import com.woniuxy.hrp.entity.Hospital;
import com.woniuxy.hrp.provider.HospitalMapperSqlProvider;
import com.woniuxy.hrp.provider.PatientMapperSqlProvider;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 医院mapper
 */
@Mapper
public interface HospitalMapper {
    /**
     * 增加医院
     * @param hospital
     */
    @Insert("insert into hrp_hospital values (null,#{name},#{description},#{address},#{telephone},#{status})")
    void add(Hospital hospital);

    /**
     * 根据医院id删除医院
     * @param id
     */
    @Delete("delete from hrp_hospital where id=#{id} ")
    void del(int id);

    /**
     * 根据医院id查找医院
     * @param id
     * @return
     */
    @Select("select * from hrp_hospital where id=#{id}")
    Hospital findById(int id);

    /**
     * 查询所有的医院
     * @return
     */
    @Select("select * from hrp_hospital")
    List<Hospital> all();

    //模糊查询医院
    @Select("select * from hrp_hospital where name like '%${name}%'")
    List<Hospital> findByName(String name);

    //修改医院
    @UpdateProvider(type = HospitalMapperSqlProvider.class,method = "updateHospitalByCondition")
    void updateByCondition(Hospital hospital);


    //删除医院(逻辑删除)
    @Update("update hrp_hospital set status='n' where id=#{id}")
    void update(int id);
    /***
     * @description: 根据医院id查询医院所有信息及拥有科室
     * @param: id
     * @return: com.woniuxy.hrp.entity.Hospital
     * @author Lrw
     * @date: 2022/8/30 17:43
     */
    @Select("select * from hrp_hospital where id=#{id}")
    @Results(id = "hospitalMap",value = {
            @Result(column = "id",property = "id",id = true),
            @Result(column = "id",property = "departments",many = @Many(select = "com.woniuxy.hrp.mapper.DepartmentMapper.selectByHospitalId")),
    })
    Hospital selectByIdWithDept(int id);

    /***
     * @description: 多条件查询
     * @param: hospital
     * @return: 满足参数条件的医院集合
     * @author Lrw
     * @date: 2022/8/30 17:42
     */
    @SelectProvider(type = HospitalMapperSqlProvider.class, method = "selectHospitalByCondition")
    @ResultMap(value = "hospitalMap")
    List<Hospital> selectByCondition(Hospital hospital);

    @Select("select * from hrp_hospital")
    List<Hospital> selectAll();

    /***
     * @description: 查所有的状态正常的医院（首页展示）
     * @return: java.util.List<com.woniuxy.hrp.entity.Hospital>
     * @author Lrw
     * @date: 2022/9/2 15:28
     */
    @Select("select * from hrp_hospital where status='y'")
    List<Hospital> selectAllHospAvailable();

    /***
     * @description: 根据医院名称模糊查询(首页 ）
     * @param: 含输入字符的所有医院
     * @return: java.util.List<com.woniuxy.hrp.entity.Hospital>
     * @author Lrw
     * @date: 2022/9/2 16:21
     */
    @Select("select * from hrp_hospital where status='y' and name like '%${name}%'")
    List<Hospital> selectByHospNameVaguely(String name);
}
